<?php

namespace App\Models;

use App\Http\Controllers\Admin\Traits\AdminTrait;
use Illuminate\Database\Eloquent\Model;

class SchoolSuppliers extends Model
{
    const OPERATE_PID = 1;
    const MODEL       = 'school_suppliers';

    use AdminTrait;

    protected $table      = 'school_suppliers';
    protected $guarded    = [];
//    protected $dateFormat = 'U';

    public static function list($data = [], $skip = 0, $size = 10)
    {
        $select = self::where([]);
        if (isset($data['school_audit_status']) && !empty($data['school_audit_status'])) {
            $select = $select->where('school_audit_status', '=', $data['school_audit_status']);
        }

        if (isset($data['admin_audit_status']) && $data['admin_audit_status'] != -1) {
            $select = $select->where('admin_audit_status', '=', $data['admin_audit_status']);
        }

        $count = $select->count();
        $list  = $select->skip($skip)->take($size)
            ->orderBy('created_at', 'desc')
            ->select(['*'])
            ->get()->toArray();

        return ['list' => $list, 'count' => $count];
    }

}
